#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2021/8/2 13:57
# @Author  : Samge
import os

from PyQt5.QtWidgets import QFileDialog, QMessageBox

from itkz.resources.utils import file_util, tip_util, config_util

# 主要样式路径
MAIN_STYLE_PATH = 'main.qss'


def get_main_style():
    """
    获取qss样式内容
    :return:
    """
    os.chdir(file_util.get_parent_path(__file__))
    return file_util.read_txt_file(MAIN_STYLE_PATH)


def get_custom_style(self):
    """
    获取自定义样式内容
    :return:
    """
    return file_util.read_txt_file(config_util.value(f"{self.name()}/custom_style_path"))


def import_style(self):
    """
    导入样式配置
    :param self:
    :return:
    """
    config_path, filetype = QFileDialog.getOpenFileName(self, "选取文件", "C:/", "Text Files (*.qss)")
    if not config_path:
        return None
    print(f'import_style: {config_path}')
    if not str(config_path).endswith('.qss'):
        tip_util.show_tip(self, "只支持导入.qss后缀的样式文件", tip_type=QMessageBox.critical)
        return None
    tip_util.show_tip(self, "导入样式成功")
    config_util.setValue(f"{self.name()}/custom_style_path", config_path)
    return config_path
